package org.fdy.bgadmin.controller.business;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.fdy.bgadmin.utils.LocalIPUtil;
import org.fdy.common.core.model.Result;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.net.InetAddress;
import java.util.Objects;

/**
 * <p>描述：</p>
 *
 * @author fangdy
 * @create 2024-09-11 17:12
 */
@Slf4j
@RestController
@RequestMapping("/test")
@RequiredArgsConstructor
@Api(tags = "测试")
public class TestController {


    @ApiOperation("本地IP地址")
    @GetMapping(value = "/ip")
    public Result<String> localIp() {
        InetAddress localHostExactAddress = LocalIPUtil.getLocalHostExactAddress();
        if (Objects.nonNull(localHostExactAddress)) {
            String hostAddress = localHostExactAddress.getHostAddress();
            log.info("本地IP地址：{}", hostAddress);
            return Result.ok(hostAddress);
        }
        return Result.ok();
    }
}
